home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / out-of-phase-102-c / OutOfPhase 1.02 Source / OutOfPhase Folder / TieTracking.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-23  |  4.8 KB  |  151 lines  |  [TEXT/KAHL]

  1. /* TieTracking.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #include "MiscInfo.h"
  26. #include "Audit.h"
  27. #include "Debug.h"
  28. #include "Definitions.h"
  29.  
  30. #include "TieTracking.h"
  31. #include "NoteObject.h"
  32. #include "Array.h"
  33. #include "Memory.h"
  34.  
  35.  
  36. typedef struct
  37.     {
  38.         long                            SourcePixelIndexX;
  39.         long                            SourcePixelIndexY;
  40.         NoteObjectRec*        SourceNote;
  41.         NoteObjectRec*        DestinationNote;
  42.     } TiePairRec;
  43.  
  44.  
  45. struct TieTrackRec
  46.     {
  47.         ArrayRec*                    ListOfRecords; /* TiePairRec's */
  48.     };
  49.  
  50.  
  51. /* create a new tie tracking record */
  52. TieTrackRec*            NewTieTracker(void)
  53.     {
  54.         TieTrackRec*        TieTracker;
  55.  
  56.         TieTracker = (TieTrackRec*)AllocPtrCanFail(sizeof(TieTrackRec),"TieTrackRec");
  57.         if (TieTracker == NIL)
  58.             {
  59.              FailurePoint1:
  60.                 return NIL;
  61.             }
  62.         TieTracker->ListOfRecords = NewArray();
  63.         if (TieTracker->ListOfRecords == NIL)
  64.             {
  65.              FailurePoint2:
  66.                 ReleasePtr((char*)TieTracker);
  67.                 goto FailurePoint1;
  68.             }
  69.         return TieTracker;
  70.     }
  71.  
  72.  
  73. /* dump the tie tracker thing */
  74. void                            DisposeTieTracker(TieTrackRec* TieTracker)
  75.     {
  76.         long                        Limit;
  77.         long                        Scan;
  78.  
  79.         CheckPtrExistence(TieTracker);
  80.         Limit = ArrayGetLength(TieTracker->ListOfRecords);
  81.         for (Scan = 0; Scan < Limit; Scan += 1)
  82.             {
  83.                 TiePairRec*            TiePair;
  84.  
  85.                 TiePair = (TiePairRec*)ArrayGetElement(TieTracker->ListOfRecords,Scan);
  86.                 ReleasePtr((char*)TiePair);
  87.             }
  88.         DisposeArray(TieTracker->ListOfRecords);
  89.         ReleasePtr((char*)TieTracker);
  90.     }
  91.  
  92.  
  93. /* find out if there is a tie source in the object for the destination. */
  94. /* the pair is removed from the list */
  95. MyBoolean                    GetTieSourceFromDestination(TieTrackRec* TieTracker,
  96.                                         long* SourcePixelX, long* SourcePixelY,
  97.                                         struct NoteObjectRec** SourceNote,
  98.                                         struct NoteObjectRec* CurrentNote)
  99.     {
  100.         long                        Limit;
  101.         long                        Scan;
  102.  
  103.         CheckPtrExistence(TieTracker);
  104.         Limit = ArrayGetLength(TieTracker->ListOfRecords);
  105.         for (Scan = 0; Scan < Limit; Scan += 1)
  106.             {
  107.                 TiePairRec*            TiePair;
  108.  
  109.                 TiePair = (TiePairRec*)ArrayGetElement(TieTracker->ListOfRecords,Scan);
  110.                 CheckPtrExistence(TiePair);
  111.                 if (TiePair->DestinationNote == CurrentNote)
  112.                     {
  113.                         *SourcePixelX = TiePair->SourcePixelIndexX;
  114.                         *SourcePixelY = TiePair->SourcePixelIndexY;
  115.                         *SourceNote = TiePair->SourceNote;
  116.                         ArrayDeleteElement(TieTracker->ListOfRecords,Scan);
  117.                         ReleasePtr((char*)TiePair);
  118.                         return True;
  119.                     }
  120.             }
  121.         return False;
  122.     }
  123.  
  124.  
  125. /* add a new tie pair to the list of tie pairs */
  126. MyBoolean                    AddTiePairToTieTracker(TieTrackRec* TieTracker,
  127.                                         struct NoteObjectRec* SourceNote, long SourcePixelX,
  128.                                         long SourcePixelY, struct NoteObjectRec* DestinationNote)
  129.     {
  130.         TiePairRec*            TiePair;
  131.  
  132.         CheckPtrExistence(TieTracker);
  133.         TiePair = (TiePairRec*)AllocPtrCanFail(sizeof(TiePairRec),"TiePairRec");
  134.         if (TiePair == NIL)
  135.             {
  136.              FailurePoint1:
  137.                 return False;
  138.             }
  139.         TiePair->SourcePixelIndexX = SourcePixelX;
  140.         TiePair->SourcePixelIndexY = SourcePixelY;
  141.         TiePair->SourceNote = SourceNote;
  142.         TiePair->DestinationNote = DestinationNote;
  143.         if (!ArrayAppendElement(TieTracker->ListOfRecords,TiePair))
  144.             {
  145.              FailurePoint2:
  146.                 ReleasePtr((char*)TiePair);
  147.                 goto FailurePoint1;
  148.             }
  149.         return True;
  150.     }
  151.